/*
 * JVM_Display2D.c
 *
 *  Created on: 24.02.2011
 *      Author: hest0053
 */
#include "board.h"
#include "JVM_Display2D.h"
#include "Display2D.h"

#include "JVM_StackFrame.h"
#include "JVM_Opcode.h"

/****************************************************************************************/
/*																						*/
/*	Function : JVM_Display2D_setPixel						Author :  Steffen Hempel 	*/
/*																	  Marco Zeltwanger	*/
/*																						*/
/*																	  					*/
/*	Description : 								   										*/
/*																						*/
/*	Version : 1.0					Date :2011.2.23			Status : Working   			*/
/*	Version : 2.0	OG				Date :2011.2.27			Status : Working   			*/
/*																						*/
/****************************************************************************************/


uint16_t JVM_Display2D_setPixel()
{
	JVM_StackFrame_t * myStackFrame;
	int32_t x;
	int32_t y;
	int32_t value;


	myStackFrame=JVM_Opcode_getActiveStackFrame();

	value = JVM_StackFrame_popIntValue(myStackFrame);
	y = JVM_StackFrame_popIntValue(myStackFrame);
	x = JVM_StackFrame_popIntValue(myStackFrame);



	Display2D_setPixel(x, y, value);

	return(STCD_OK);
}

/****************************************************************************************/
/*																						*/
/*	Function : JVM_Display2D_setLED							Author :  Steffen Hempel 	*/
/*																	  Marco Zeltwanger	*/
/*																						*/
/*																	  					*/
/*	Description : 								   										*/
/*																						*/
/*	Version : 1.0					Date :2011.2.23			Status : Working   			*/
/*	Version : 2.0	OG				Date :2011.2.26			Status : Working   			*/
/*																						*/
/****************************************************************************************/


uint16_t JVM_Display2D_setTopLED()
{

	JVM_StackFrame_t * myStackFrame;
	int32_t index;
	int32_t value;

	myStackFrame=JVM_Opcode_getActiveStackFrame();

	value = JVM_StackFrame_popIntValue(myStackFrame);
	index = JVM_StackFrame_popIntValue(myStackFrame);

	if((index < 0) || (index>12))
		return(STCD_OK);;

	Display2D_setLED(index,value);
	return(STCD_OK);
}



/****************************************************************************************/
/*																						*/
/*	Function : JVM_Display2D_setLED							Author :  Steffen Hempel 	*/
/*																	  Marco Zeltwanger	*/
/*																						*/
/*																	  					*/
/*	Description : 								   										*/
/*																						*/
/*	Version : 1.0					Date :2011.2.23			Status : Working   			*/
/*	Version : 2.0	OG				Date :2011.2.26			Status : Working   			*/
/*																						*/
/****************************************************************************************/


uint16_t JVM_Display2D_setSideLED()
{

	JVM_StackFrame_t * myStackFrame;
	int32_t index;
	int32_t value;

	myStackFrame=JVM_Opcode_getActiveStackFrame();

	value = JVM_StackFrame_popIntValue(myStackFrame);
	index = JVM_StackFrame_popIntValue(myStackFrame);
	if((index < 0) || (index>3))
		return(STCD_OK);

	Display2D_setLED(index+12,value);
	return(STCD_OK);
}

/****************************************************************************************/
/*																						*/
/*	Function : JVM_Display2D_repaint							Author :  OG		 	*/
/*																						*/
/*																	  					*/
/*	Description : 								   										*/
/*																						*/
/*	Version : 1.0					Date :2011.2.23			Status : Working   			*/
/*																						*/
/****************************************************************************************/


uint16_t JVM_Display2D_repaint()
{
	Display2D_repaint();
	return(STCD_OK);
}



/****************************************************************************************/
/*																						*/
/*	Function : JVM_Display2D_clear							Author :  Steffen Hempel 	*/
/*																	  Marco Zeltwanger	*/
/*																						*/
/*																	  					*/
/*	Description : 								   										*/
/*																						*/
/*	Version : 1.0					Date :2011.2.23			Status : Working   			*/
/*																						*/
/****************************************************************************************/


uint16_t JVM_Display2D_clear()
{
	Display2D_clear();
	return(STCD_OK);
}


/****************************************************************************************/
/*																						*/
/*	Function : JVM_Display2D_fillAll						Author :  OG			 	*/
/*																						*/
/*																	  					*/
/*	Description : 								   										*/
/*																						*/
/*	Version : 1.0					Date :2011.3.26			Status : Working   			*/
/*																						*/
/****************************************************************************************/


uint16_t JVM_Display2D_fillAll()
{
	Display2D_fillAll(JVM_StackFrame_popIntValue(JVM_Opcode_getActiveStackFrame()));
	return(STCD_OK);
}

/****************************************************************************************/
/*																						*/
/*	Function : JVM_Display2D_rowCount						Author : OG					*/
/*																						*/
/*	Description : 								   										*/
/*																						*/
/*	Version : 1.0					Date :2011.2.27			Status : Working   			*/
/*																						*/
/****************************************************************************************/

uint16_t JVM_Display2D_rowCount()
{
	JVM_StackFrame_pushIntValue(JVM_Opcode_getActiveStackFrame(),DISPLAY2D_ROW_COUNT);
	return(STCD_OK);
}



/****************************************************************************************/
/*																						*/
/*	Function : JVM_Display2D_columCount						Author : OG					*/
/*																						*/
/*	Description : 								   										*/
/*																						*/
/*	Version : 1.0					Date :2011.2.27			Status : Working   			*/
/*																						*/
/****************************************************************************************/

uint16_t JVM_Display2D_columCount()
{
	JVM_StackFrame_pushIntValue(JVM_Opcode_getActiveStackFrame(),DISPLAY2D_COLUMN_COUNT);
	return(STCD_OK);
}

/****************************************************************************************/
/*																						*/
/*	Function : JVM_Display2D_columCount						Author : OG					*/
/*																						*/
/*	Description : 								   										*/
/*																						*/
/*	Version : 1.0					Date :2011.3.25			Status : Working   			*/
/*																						*/
/****************************************************************************************/

uint16_t JVM_Display2D_print8x8Char()
{
	JVM_StackFrame_t * myStackFrame;
	int32_t index;
	int32_t x;
	int32_t y;
	int32_t color;


	myStackFrame=JVM_Opcode_getActiveStackFrame();

	color = JVM_StackFrame_popIntValue(myStackFrame);
	y = JVM_StackFrame_popIntValue(myStackFrame);
	x = JVM_StackFrame_popIntValue(myStackFrame);
	index = JVM_StackFrame_popIntValue(myStackFrame);


	Display2D_print8x8Char(index,x, y, color);


return(STCD_OK);
}


/****************************************************************************************/
/*																						*/
/*	Function : JVM_Display2D_columCount						Author : OG					*/
/*																						*/
/*	Description : 								   										*/
/*																						*/
/*	Version : 1.0					Date :2011.3.25			Status : Working   			*/
/*																						*/
/****************************************************************************************/

uint16_t JVM_Display2D_print5x5Char()
{
	JVM_StackFrame_t * myStackFrame;
	int32_t index;
	int32_t x;
	int32_t y;
	int32_t color;


	myStackFrame=JVM_Opcode_getActiveStackFrame();

	color = JVM_StackFrame_popIntValue(myStackFrame);
	y = JVM_StackFrame_popIntValue(myStackFrame);
	x = JVM_StackFrame_popIntValue(myStackFrame);
	index = JVM_StackFrame_popIntValue(myStackFrame);


	Display2D_print5x5Char(index,x, y, color);


return(STCD_OK);
}


/****************************************************************************************/
/*																						*/
/*	Function : JVM_Display2D_dravLine						Author : OG					*/
/*																						*/
/*	Description : 								   										*/
/*																						*/
/*	Version : 1.0					Date :2011.3.28			Status : Working   			*/
/*																						*/
/****************************************************************************************/

uint16_t JVM_Display2D_dravLine()
{
	JVM_StackFrame_t * myStackFrame;
	int8_t x;
	int8_t y;
	int8_t dx;
	int8_t dy;
	int color;

	myStackFrame=JVM_Opcode_getActiveStackFrame();

	color = JVM_StackFrame_popIntValue(myStackFrame);
	dy = JVM_StackFrame_popIntValue(myStackFrame);
	dx = JVM_StackFrame_popIntValue(myStackFrame);
	y = JVM_StackFrame_popIntValue(myStackFrame);
	x = JVM_StackFrame_popIntValue(myStackFrame);

	Display2D_dravLine( x, y, dx, dy, color );

	return(STCD_OK);
}



/****************************************************************************************/
/*																						*/
/*	Function : JVM_Bitmap2D_not								Author : OG					*/
/*																						*/
/*	Description : 								   										*/
/*																						*/
/*	Version : 1.0					Date :2011.5.2			Status : working   			*/
/*																						*/
/****************************************************************************************/

uint16_t JVM_Display2D_display2DBitmap()
{
	JVM_HandleNumber_t bitmapHandle;
	JVM_HandleNumber_t viewportHandle;

	uint16_t  * addres;
	Dimension2D_t size;
	Dimension2D_t origin;
	uint16_t *viewport;

	viewportHandle=JVM_Opcode_popReference();
	bitmapHandle=JVM_Opcode_popReference();
	origin.y=JVM_Opcode_popIntValue();
	origin.x=JVM_Opcode_popIntValue();

	JVM_Handle_getRealAddres(bitmapHandle,(uint32_t*)&addres);
	JVM_Handle_getRealAddres(viewportHandle,(uint32_t*)&viewport);

	addres+=3;
	size.x=*addres++;
	size.y=*addres++;

	viewport+=3;


	Display2D_display2DBitmap(&origin,&size,addres,viewport);

	return(STCD_OK);
}

